package com.sudo.common.utils;

import java.util.regex.Pattern;

public class PatternUtil {
    // 网址
    final public static String URL_PATTERN = "^((https|http|ftp|rtsp|mms)?:\\/\\/)[^\\s]+";
    // 手机号
    final public static String PHONE_PATTERN = "^(13[0-9]|14[5|7]|15[0-9]|18[0-9]|19[4|5])\\d{8}$";
    // 英文和数字
    final public static String Abc123_PATTERN = "^[A-Za-z0-9]+$";
    // 4位英文和数字
    final public static String Abc123_PATTERN_4 = "^[A-Za-z0-9]{4}$";
    // 5位英文和数字
    final public static String Abc123_PATTERN_5 = "^[A-Za-z0-9]{5}$";

    // 判断字符串非空且为非负整数
    final public static String isNonNegativeInteger = "^[0-9]+[0-9]*$";

    final public static String email = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";


    public static boolean isMatches(String patternStr, String str) {
        Pattern pattern = Pattern.compile(patternStr);
        return pattern.matcher(str).matches();
    }

    // 判断字符串非空且为非负整数
    public static boolean isNonNegativeInteger(String str){
        Pattern pattern = Pattern.compile(isNonNegativeInteger);
        return pattern.matcher(str).matches();
    }
}
